<?php
class C_login extends CI_Controller {

	function C_login()
	{
		parent::__construct();
		$this->load->model('m_login', '', TRUE);
		$this->load->model('m_main', '', TRUE);
		
		checkLogin();
	}
	
	function index()
	{
		$data["background"]=$this->m_main->get_background();
		$this->load->vars($data);
		$this->load->view('v_login');
	}
	
	
	function verify() 
	{
		if( isset($_POST['username']) && isset($_POST['password'])) 
		{
			$u	= preg_replace('[^a-zA-Z0-9_]','',$_POST['username']);
			//echo $u;
			$pw	= md5($_POST['password']);
			$_SESSION["user_post"]=$u;
			$_SESSION["msg"]="";
			$auth = $this->m_login->verifyUser($u, $pw);

			if($auth){
	            	echo "{success:true}";
			} else{
					echo "{success:false,msg:'Username or Password incorrect'}";
			}
        } else {		
			
        	 echo "{success:false,msg:'Please fill the Requirement Field!'}";
        }
	}
	
	
	function logout(){
		setLogout();
		/* $sesslog=array(
				'SESSION_PERIODE'=>'',
				'SESSION_PERIODE_AWAL'=>'',
				'SESSION_KURS_ID'=>'',
				'SESSION_KURS_NAMA'=>'',
				'SESSION_KURS_NILAI'=>'',
				'SESSION_CABANG'=>'',
				'SESSION_CABANG_KODE'=>'',
				'SESSION_CABANG_NAMA'=>'',
				'SESSION_CABANG_COMPANY'=>'',
				'SESSION_CABANG_COMPANY_NAME'=>'',
				'SESSION_JBELI'=>'',
				'SESSION_JJUAL'=>'',
				'SESSION_JKASBANK'=>''
			);
					
		$this->session->unset_userdata($sesslog);
		
		$sess_users=array(
						'SESSION_USERID'=>'',
						'SESSION_GROUPID'=>'',
						'SESSION_GROUPNAMA'=>''
					);
		$this->session->unset_userdata($sess_users);
			
		$this->session->set_flashdata('error',"You've been logged out!");
		redirect('','location',302); */
	 }
	 
}
?>